package ioperations;

import book.Book;
import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏李涛
 * Date: 2024-05-24
 * Time: 20:50
 */
public class BorrowOperation implements IOperation{
    @Override
    public void work(BookList bookList) {
        System.out.println("借阅图书");

       int currentSize = bookList.getUsedSize();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入你要借阅的图书");
        String name = scanner.nextLine();

        for (int i = 0; i < currentSize; i++) {
            //遍历，书架，已初始化的书
            Book book = bookList.getBook(i);
            if (book.getName().equals(name)) {
                //看看isBorrowed返回,ture(已借出),还是false(未借出)
                if (book.isBorrowed()) {
                    System.out.println("该书已经被借出");
                    return;
                }

                book.setBorrowed(true);//置为借出
                System.out.println("借阅成功");
                return;
            }
        }
        System.out.println("没有找到你要借阅的那本书");
    }
}
